package com.yb.source.node;

/**
 * 队列：先入先出
 */
public class Queue {

    Node first, last;

    /**
     * 入队:到队尾
     * @param node
     */
    public void enqueue(Node node) {
        if (first == null) {
            first = node;
            last = first;
        } else {
            last.next = node;
            last = node;
        }
    }

    /**
     * 出队:出first
     * @return
     */
    public Node dequeue() {
        if (first == null) {
            return null;
        } else {
            Node temp = new Node(first.val);
            first = first.next;
            return temp;
        }
    }
}
